﻿using LAVAA.BL.Control;
using LAVAA.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LAVAA.WEB.Controllers
{
    public class RewardsController : Controller
    {
        //
        // GET: /Reward/

        public ActionResult ListRewardTypes()
        {
            return View(new RewardFacade().getRewardTypes());
        }

        //
        // GET: /Reward/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Reward/Create

        public ActionResult CreateRewardType()
        {
            return View(new RewardType());
        }

        //
        // POST: /Reward/Create

        [HttpPost]
        public ActionResult CreateRewardType(RewardType rewType)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    new RewardFacade().AddRewardType(rewType);
                }
                return RedirectToAction("ListRewardTypes");

            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return View();
            }
        }

        //
        // GET: /Reward/Edit/5

        public ActionResult EditRewardType(Guid id)
        {
            var a = new RewardFacade().GetById(id);
            return View(a);
        }

        //
        // POST: /ActivityType/Edit/5

        [HttpPost]
        public ActionResult EditRewardType(Guid id, RewardType reward)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    new RewardFacade().UpdateRewardType(reward);
                    return RedirectToAction("ListRewardTypes");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }
            return View(reward);
        }

        //
        // GET: /Reward/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Reward/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
